package com.entor.hqj.util;

import android.widget.RadioGroup;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by qingjie on 2018/3/23.
 */

public class StringUtil {
   static SimpleDateFormat sdf =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static String getTimeFormat(String t1,Date t2){
        try {
            Date d = sdf.parse(t1);
            Long l1 = d.getTime();
            Long l2 = t2.getTime();
            long l3 = Math.abs(l1-l2);
            long day = l3/24/60/60/1000;
            long hour = l3/60/60/1000%24;
            long min = l3/60/1000%60;
            long sec = l3/1000%60;
            return addZero(day)+"天"+addZero(hour)+"小时"+addZero(min)+"分钟"+addZero(sec)+"秒";
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public static String addZero(long i){
        if(i<10){
            return "0"+i;
        }
        return i+"";
    }

    public static String changeStr(String str ,int length){
        boolean b = false;
        if(str.length()<length){
            b = true;
            length = str.length();
        }
        return str.substring(0,length)+(b?"":"...");
    }

}
